1. Field of the Invention
This invention relates to the field of microprocessors and, more particularly, to instruction patching mechanisms within microprocessors.
2. Description of the Relevant Art
Superscalar microprocessors achieve high performance by executing multiple instructions per clock cycle and by choosing the shortest possible clock cycle consistent with the design. As used herein, the term "clock cycle" refers to an interval of time accorded to various stages of an instruction processing pipeline within the microprocessor. Storage devices (e.g. registers and arrays) capture their values according to the clock cycle. For example, a storage device may capture a value according to a rising or falling edge of a clock signal defining the clock cycle. The storage device then stores the value until the subsequent rising or falling edge of the clock signal, respectively. The term "instruction processing pipeline" is used herein to refer to the logic circuits employed to process instructions in a pipelined fashion. Although the pipeline may be divided into any number of stages at which portions of instruction processing are performed, instruction processing generally comprises fetching the instruction, decoding the instruction, executing the instruction, and storing the execution results in the destination identified by the instruction.
Microprocessor designers often design their products in accordance with the x86 microprocessor architecture in order to take advantage of its widespread acceptance in the computer industry. Because the x86 microprocessor architecture is pervasive, many computer programs are written in accordance with the architecture. X86 compatible microprocessors may execute these computer programs, thereby becoming more attractive to computer system designers who desire x86-capable computer systems. Such computer systems are often well received within the industry due to the wide range of available computer programs.
The x86 microprocessor architecture specifies a variable length instruction set (i.e. an instruction set in which various instructions employ differing numbers of bytes to specify that instruction). For example, the 80386 and later versions of x86 microprocessors employ between 1 and 15 bytes to specify a particular instruction. Instructions have an opcode, which may be 1-2 bytes, and additional bytes may be added to specify addressing modes, operands, and additional details regarding the instruction to be executed. Certain instructions within the x86 instruction set are quite complex, specifying multiple operations to be performed. For example, the PUSHA instruction specifies that each of the x86 registers be pushed onto a stack defined by the value in the ESP register. The corresponding operations are a store operation for each register, and decrements of the ESP register between each store operation to generate the address for the next store operation.
Often, complex instructions are classified as MROM instructions. MROM instructions are transmitted to a microcode instruction unit within the microprocessor, which decodes the complex MROM instruction and produces two or more simpler microcode instructions for execution by the microprocessor. The simpler microcode instructions corresponding to the MROM instruction are typically stored in a read-only memory (ROM) within the microcode unit. The microcode instruction unit determines an address within the ROM at which the microcode instructions are stored, and transfers the microcode instructions out of the ROM beginning at that address. Multiple clock cycles may be used to transfer the entire set of instructions within the ROM that correspond to the MROM instruction.
Different instructions may require differing numbers of microcode instructions to effectuate their corresponding functions. Additionally, the number of microcode instructions corresponding to a particular MROM instruction may vary according to the addressing mode of the instruction, the operand values, and/or the options included with the instruction. The microcode instruction unit issues the microcode instructions into the instruction processing pipeline of the microprocessor. The microcode instructions are thereafter executed in a similar fashion to other instructions. It is noted that the microcode instructions may be instructions defined within the instruction set, or may be custom instructions defined for the particular microprocessor.
Conversely, less complex instructions are decoded by hardware decode units within the microprocessor, without intervention by the microcode unit. The terms "directly-decoded instruction" and "fastpath instruction" will be used herein to refer to instructions which are decoded and executed by the microprocessor without the aid of a microcode instruction unit. As opposed to MROM instructions which are reduced to simpler instructions which may be handled by the microprocessor, directly-decoded instructions are decoded and executed via hardware decode and functional units included within the microprocessor.
New microprocessor designs typically are produced in iterative steps. Microprocessor prototypes are fabricated on silicon chips, and then are tested using various techniques to determine if the processor design, as fabricated, will perform satisfactorily. As errors are detected, the microprocessor design is modified and new prototypes are produced embodying the modified design. This seemingly continuous process of designing, fabricating and testing a processor design is referred to as "debugging."
One of the portions of the microprocessor design that requires debugging is the microcode. As the microprocessor is tested, errors may be discovered in the microcode instructions. Because of the limited access to the microcode, the microcode is typically changed only when new prototypes are produced for successive designs. Furthermore, when errors are found in the microcode, all related debugging is typically stopped, because it is inefficient to modify the processor hardware when the associated microcode will be revised. Consequently, further debugging in related areas is halted until the new prototypes are produced.
When errors (or bugs) are found in microcode instructions, these errors are documented to system designers. Typically, the system designers run simulations to find ways to change the microcode to correct the errors detected. These changes cannot be effectively tested until the next prototype is produced with the changes to the microcode embedded in the internal ROM of the subsequent processor prototype. A problem with this approach is that the changes to the microcode cannot be easily or completely verified in the system environment before the changes are committed to silicon. This procedure can greatly increase the cost and time expended during the design process, as unverified changes are made to the microcode and incorporated in a subsequent prototype of the microprocessor, only to fail.
One way to overcome the above problem is to incorporate a technique for patching existing instructions with substitute microcode instructions. When an instruction that needs to be patched is encountered, the instruction fetching mechanism of the microprocessor accesses the substitute microcode instruction from external memory and loads the substitute microcode instruction into the instruction cache. As used herein, the term "external memory" refers to any storage device external to the microprocessor. The substitute microcode instruction, or patched microcode instruction, is then dispatched into the instruction processing pipeline as a substitute for the existing instruction.
Unfortunately, fetching patched microcode instructions from external memory causes a significant portion of the microprocessor to be redesigned. The instruction fetching and alignment mechanisms are designed for x86 type instructions, not microcode instructions. Microcode instructions are typically a different length then x86 instructions and are encoded differently. Therefore, the instruction fetching mechanism, instruction cache and other circuitry are not designed to handle microcode instructions. To implement the above described patching mechanism, this circuitry must be redesigned to accommodate patched microcode instructions.